package com.alex.method_03;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

//标注这个类是一个切面, 相当于xml中的 <aop:aspect ref="myLog">
@Aspect
public class MyLog {

    @Pointcut("execution(* com.alex.UserServiceImpl.*(..))")
    private void usp() {}

    @Before("usp()")
    public void before() {
        System.out.println("before...");
    }

    @After("usp()")
    public void after() {
        System.out.println("after...");
    }

    @AfterReturning("usp()")
    public void afterReturning() {
        System.out.println("afterReturning...");
    }

    @Around("usp()")
    public void around(ProceedingJoinPoint jp) {
        try {
            System.out.println("...before...");
            jp.proceed();
            System.out.println("...after...");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
